﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
namespace BISPOS
{
    
    public partial class SelectPaymentTypeForm : DevExpress.XtraEditors.XtraForm
    {
        POSForm pOSForm;
        BISPOS.Repository.InvoiceRepository invoiceRepository = new Repository.InvoiceRepository();
        public SelectPaymentTypeForm(POSForm _pOSForm)
        {
            InitializeComponent();
            pOSForm = _pOSForm;
            paymentTypeListlinqServerModeSource.QueryableSource = invoiceRepository.AllPaymentTypes().AsQueryable();
        }


        private void SelectPaymentTypeForm_Shown(object sender, EventArgs e)
        {
            allPaymentTypeListBoxControl.Focus();
        }

        private void allPaymentTypeListBoxControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = "เลือกประเภทการชำระเงิน - " + allPaymentTypeListBoxControl.SelectedItems.OfType<PaymentType>().FirstOrDefault().Name;
        }

        private void allPaymentTypeListBoxControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                pOSForm.ChangePaymentType(allPaymentTypeListBoxControl.SelectedItems.OfType<PaymentType>().FirstOrDefault());
                this.Close();
            }
            if(e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }




    }
}